home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MVUPDAT3.ZIP / DMVWORD.ZIP / DMVWORD.TXT < prev   
Text File  |  1995-11-26  |  23KB  |  484 lines

  1.             ╔═══════════════════════════════════════════════════╗
  2.             ║             Document Macro Viruses                ║
  3.             ║  Yes, you can spread a virus with a data file...  ║
  4.             ║                 Joel McNamara                     ║
  5.             ╚═══════════════════════════════════════════════════╝
  6.  Overview
  7.  
  8.  In early December of 1994, users of America On-Line and the Internet
  9.  were nervously opening their electronic mail.  Rumors were flying about
  10.  e-mail with the title of Goodtimes.  If you opened the mail, your
  11.  computer was instantly infected with a virus.  Most experts scoffed at
  12.  the possibility.  After all, it takes an executable binary to be able to
  13.  pass on a virus.  DOS users occassionally have been plagued with ANSI
  14.  bombs (a text file that when viewed with the TYPE command remaps your
  15.  keyboard), but other than that, simply looking at data has never
  16.  resulted in anything more harmful than eye strain.  After investigation,
  17.  the GoodTimes e-mail virus was deemed to be a hoax.  But is there more
  18.  to the story?
  19.  
  20.  In truth, there is some risk of an e-mail propogated virus in a mail
  21.  system that uses embedded objects (MIME or OLE, for example).  An
  22.  embedded application that contains a virus or trojan horse could be sent
  23.  in an e-mail message, and when executed, infect or damage the system.
  24.  E-mail software that automatically runs embedded objects in a receieved
  25.  message (such as plays a sound file, displays an image, or runs an
  26.  application) is at particular risk from anonymously sent virus mail.
  27.  
  28.  While some security and virus experts have considered the potential for
  29.  document-based viruses, discussions have been mostly theoretical in
  30.  nature.  There is agreement though, that viruses passed on by documents
  31.  could pose a significant threat to computer users.
  32.  
  33.  This paper moves beyond theory, by presenting preliminary research on an
  34.  actual document-based virus created in Microsoft Word for Windows.  The
  35.  paper discusses the concept of a document macro virus, potential
  36.  threats, how this type of a virus functions, and preventative measures
  37.  for dealing with it.
  38.  
  39.  Document Macro Viruses
  40.  
  41.  While virus creators have concentrated on code that works at the
  42.  operating system level, they have for the time being, neglected
  43.  applications.  Most business applications, such as spreadsheets, word
  44.  processors, and data-bases, come with fairly powerful macro languages.
  45.  Many applications have the ability to auto-execute macros.  This
  46.  combination provides a serious threat to computer users who have been
  47.  taught that data files cannot harm your system.
  48.  
  49.  I use the term document macro virus (or DMV for short) to describe this
  50.  type of potentially malicious code.  Some characteristics of a DMV
  51.  include:
  52.  
  53.  A DMV is written in the macro language of an application.  It exploits
  54.  the application's ability to automatically execute the macro on some
  55.  event, such as opening or closing a document.  Once this event occurs in
  56.  a document that hosts the DMV, the virus spreads (or some form of trojan
  57.  horse code is executed).  Unlike a conventional virus or trojan horse
  58.  where the malicious code is in the executable, a DMV uses its creator
  59.  application as the agent to execute the code.
  60.  
  61.  DMVs are extremely simple to create.  Most macro languages are a
  62.  superset of BASIC, which is much easier to program in than assembly
  63.  langauge favored by most virus writers.  As many macro languages support
  64.  the ability to call external routines (such as functions in .DLLs), the
  65.  macro language can easily be extended to create sophisticated viruses.
  66.  
  67.  On a simplified level, DMVs tend to be application-specific in nature.
  68.  This means the virus only infects documents of the same data type, for
  69.  example, all Microsoft Word for Windows documents.  Most macro languages
  70.  are not cross-application compatible (for example, a Word DMV document
  71.  that was imported into Ami Pro, would likely not pass the virus on).  An
  72.  exception may be Microsoft's common macro language, Visual Basic for
  73.  Applications.  It is likely an advanced DMV could be written with VBA
  74.  that could move from one application to another.
  75.  
  76.  Since a DMV is application specific, it is theoretically possible a
  77.  document could pass a virus from one platform to another (i.e.
  78.  Intel-based system running Windows, to Motorola/Power PC-based Macintosh
  79.  system).  This makes a DMV unique from normal viruses, which tend to be
  80.  platform specific due to the nature of their coding.
  81.  
  82.  Current virus checking software does not support identifying DMVs.
  83.  DMVs do not exhibit standard virus characteristics such as altered MBRs,
  84.  or specific data in memory or executable files.
  85.  
  86.  Obviously, there are numerous security and privacy risks to the user
  87.  who unknowingly uses a document that hosts a DMV.  These are limited
  88.  only by the imagination of the person who creates the DMV.  A few
  89.  malacious actions that are relatively easy to implement include:
  90.  
  91.  Infecting your computer with a virus (obviously) - Deleting files on
  92.  your hard disk - Renaming existing files - Copying personal files from
  93.  your hard disk to a network location where they could be retrieved later
  94.  by someone else - Sending sensitive files from your hard disk to an
  95.  e-mail address via MAPI (Windows)
  96.  
  97.  It's important to note that these risks are not exclusive to Word for
  98.  Windows.  Any application that supports automatic macros is a potential
  99.  threat.
  100.  
  101.  If you're using Word for Windows 6.0 to read this paper, in its original
  102.  formatted form, closing the document will execute a sample,
  103.  non-destructive version of a DMV (see below for details on how it
  104.  actually works).  Dialog boxes show you each step as it is executed.  If
  105.  you're cautious, which you should be, choose the Macro command from the
  106.  Tools menu.  Select AutoClose and Edit to examine the commented macro
  107.  (source code is included at the end of this paper).  If you're very
  108.  cautious, you can delete the macro before closing this document.
  109.  
  110.  How the Word DMV Works
  111.  
  112.  Microsoft Word for Windows uses a macro language called WordBasic.  It
  113.  also supports a series of automatic macros.  If a macro has a reserved
  114.  name, it automatically executes on a specific event.  For example:
  115.  
  116.          Macro name              Runs
  117.  
  118.          AutoExec                When you start Word
  119.          AutoNew                 When you create a new document
  120.          AutoOpen                When you open a document
  121.          AutoClose               When you close a document
  122.          AutoExit                When you quit Word
  123.  
  124.  The sample Word DMV contained in this document is named AutoClose, so
  125.  each time the document is closed, the macro is executed.  This action
  126.  takes place regardless of whether the file is opened from a disk or
  127.  embedded as an object in e-mail.
  128.  
  129.  Word for Windows stores macros, as well as styles, in document templates
  130.  (.DOT files).  Global macros are stored in the NORMAL.DOT file.
  131.  
  132.  The first action the Word DMV takes is to look in NORMAL.DOT to see if
  133.  an AutoClose macro already is present.  If it isn't, it copies itself
  134.  into NORMAL.DOT.  (The sample does not perform an execute-only copy.
  135.  Such a copy prevents the user from editing the macro to examine it.)  If
  136.  an AutoClose macro is present, it doesn't infect the file.  (It is
  137.  possible, although unlikely, that a legitimate AutoClose macro may be in
  138.  NORMAL.DOT.  The macro doesn't check the check to see if it is the DMV.)
  139.  
  140.  Once NORMAL.DOT is infected, each time any document is closed while in
  141.  Word, the DMV macro executes.
  142.  
  143.  The method described above produces a virus that is limited to only
  144.  infecting users who open and close the DMV.DOC file.  (This raises
  145.  interesting possibilities for targeting a specific segment of a user
  146.  population for some malacious action.  For example, a DMV entitled
  147.  WAREZ.DOC could be anonymously posted to a pirate software bulletin
  148.  board.  The document would contain legitimate information to encourage
  149.  redistribution, but host a DMV that randomly deleted hard drive files.)
  150.  
  151.  As stated earlier, Word only stores macros in document templates.  You
  152.  cannot add a macro to a normal Word document (.DOC) file.  This appears
  153.  to eliminate the ability to be able to spread a DMV virus from the
  154.  source to other documents (which would dramatically increase the spread
  155.  of the virus).
  156.  
  157.  However, there is a way around this limitation.  A Word .DOT template is
  158.  very similar in format to a normal .DOC file.  The two have the same
  159.  appearance and functionality when opened in Word.  In fact, this
  160.  document was originally a .DOT file (so the sample macro could be
  161.  inserted), but renamed with a .DOC extension.
  162.  
  163.  To infect other documents, the DMV macro in NORMAL.DOT checks the
  164.  current document to see if it has already has been infected with the
  165.  macro.  If it hasn't, the macro saves the file as a document template.
  166.  This generates a saving file display at the bottom of the screen
  167.  (which isn't suspicious, since many users use auto-save). Word now
  168.  treats the current document as a template, and the DMV macro in
  169.  NORMAL.DOT can copy itself into the current document.
  170.  
  171.  File extensions are very deceptive.  Although the document still has a
  172.  .DOC extension, it is now a template.  When Word opens the document, it
  173.  doesn't care what extension the file has.  It reads the file and
  174.  determines if it is in a format it process.  The only clue that a normal
  175.  document has been saved as a template is when you choose the Save As
  176.  command in the File menu.  Word attempts to force you to save the
  177.  template in a default directory that contains other Word templates.  The
  178.  other clue is Word prompts you if you want to save changes when you
  179.  close, even if you haven't editted the document.
  180.  
  181.  The end of the macro contains code that isn't related to the actual
  182.  spreading of the virus.  The Word DMV just displays a dialog box that
  183.  indicates this is a point where code would be executed.  Obviously, it
  184.  is up to the imagination of the creator as to what code is placed here.
  185.  If the virus portion of the macro was removed, the DMV becomes a trojan
  186.  horse.
  187.  
  188.  The Word DMV is very simplistic.  It uses standard macro commands to
  189.  propogate the virus.  However, since Word Basic supports the ability to
  190.  call API routines in .DLLs, a much more sophisticated virus that could
  191.  infect the operating system or other applications could be created.
  192.  
  193.  As multiple-platform software usually shares common code, it seems
  194.  reasonable that a DMV could be passed on from one platform to another.
  195.  For example, if a Word for Windows document is infected, transferred to
  196.  a Macintosh disk, then loaded into Macintosh Word, the DMV would likely
  197.  infect the Mac version of Word.  I haven't tested this yet, but it seems
  198.  to be a probable occurance.
  199.  
  200.  As stated before, this is not a problem exclusive to Word for Windows
  201.  (preliminary research seems to indicate that Excel has even more
  202.  vulnerabilities) or Microsoft-specific products.  While a complete
  203.  survey of business software has not been completed, automatic macros
  204.  seem to be common in many applications produced by a variety of vendors.
  205.  
  206.  Word DMV Cookbook
  207.  
  208.  Someone with a suspicious nature might think this document has been
  209.  altered in some way (beyond just using macros) to produce the Word DMV.
  210.  To disprove this, run Word for Windows 6.0 and perform the following
  211.  steps.
  212.  
  213.  1. Create a macro named AutoClose (it's up to you what you want the
  214.  macro to do). 2. Save it to the NORMAL.DOT template (the default). 3. Go
  215.  to File Manager and copy the NORMAL.DOT file to TEST.DOT. 4. Choose
  216.  Macro from the Tools menu. 5. Delete the AutoClose macro from
  217.  NORMAL.DOT. 6. Open TEST.DOT (it will be blank). 7. Enter some text so
  218.  it appears to be a normal document and save. 8. Go to the File Manager
  219.  and rename TEST.DOT to TEST.DOC. 9. Open TEST.DOC with Word.  When the
  220.  document is closed, the macro will execute.
  221.  
  222.  Removing the Word DMV
  223.  
  224.  Removing the Word DMV is relatively easy.  First run Word, then:
  225.  
  226.  - If an infected file is open, choose the Macro command from the Tools
  227.  menu.  Delete the AutoClose macro from the open document and NORMAL.DOT.
  228.  
  229.  - If no documents are open, choose the Macro command in the File menu.
  230.  Delete the AutoClose macro from NORMAL.DOT.
  231.  
  232.  Dealing with DMVs
  233.  
  234.  The only current protection against DMVs is manually examining any
  235.  document with the creator application to see if suspect macros are
  236.  present.  This is obviously extremely time and labor intensive.
  237.  
  238.  The virus research community should make an effort to identify all
  239.  applications with automatic macro capabilities.  This should be a
  240.  relatively easy task.  The functionality and characteristics should be
  241.  studied to assess threat potential and identify means of detection.  For
  242.  example, Word DMVs should be easy to identify, since the macro code
  243.  appears to be saved as ASCII text.  A simple string search could be
  244.  performed on .DOC and .DOT files to look for AutoExec, AutoOpen,
  245.  AutoClose, etc.  Existing virus tools should be modified to identify
  246.  potential DMV host files.
  247.  
  248.  Software manufacturers need to modify future versions of their
  249.  applications to limit the potential damage an automatic macro could
  250.  cause.  It would be very simple to code an option where a dialog box
  251.  prompts a user whether they want to execute an automatic macro.  By
  252.  default, this option would be turned on.  The user would have the choice
  253.  of turning the option off if they wanted automatic macros executed with
  254.  no confirmation.
  255.  
  256.  Users need to be aware that DMVs are real and can pose a significant
  257.  threat to their data security.  Automatic macros are virtually unknown
  258.  to the general user population.  Steps should be taken to educate people
  259.  without causing panic.
  260.  
  261.  Protecting Yourself from Word DMVs
  262.  
  263.  Any automatic macro is easily detected by choosing the Macro command
  264.  from Word's Tool menu.  A suspicious macro can be examined or deleted
  265.  (hopefully, before it executes).
  266.  
  267.  Microsoft provides two methods of disabling automatic macros in Word.
  268.  
  269.  To quote from Document Q96565 in Microsoft's product support Knowledge
  270.  Base:
  271.  
  272.          SUMMARY
  273.  
  274.  To prevent a Microsoft Word for Windows auto macro from running, hold
  275.  down the SHIFT key when you perform the action that triggers the macro.
  276.  AutoExec, AutoNew, AutoOpen, AutoClose, and AutoExit are the auto macros
  277.  in Word for Windows.
  278.  
  279.          MORE INFORMATION
  280.  
  281.  When opening a Word for Windows document that is associated with a
  282.  template that contains an AutoOpen macro, hold down the SHIFT key until
  283.  the document is completely opened. Depressing the SHIFT key prevents the
  284.  action that triggers the macro.
  285.  
  286.  When opening a new Word for Windows document based on a template that
  287.  contains an AutoNew macro, hold down the SHIFT key until the new
  288.  document is opened.
  289.  
  290.  To prevent a Word for Windows AutoExec macro from executing, do one of
  291.  the following:
  292.  
  293.   - At the command prompt, type "win winword /m" (without the quotations
  294.  marks) and press ENTER.
  295.  
  296.   -or-
  297.  
  298.   - Select the Word for Windows program icon in Program Manager. From the
  299.  File menu, choose Properties. Add the /m switch to the current command
  300.  line parameter (for example, "C:\WINWORD\WINWORD.EXE /m").
  301.  
  302.   -or-
  303.  
  304.   - Press and hold down the SHIFT key while double-clicking the Word for
  305.  Windows program icon.
  306.  
  307.  In Word for Windows version 6.0, you can use the following command line
  308.  to disable all auto macros, including AutoExec:
  309.  
  310.     C:\WINWORD\WINWORD.EXE /mDisableAutoMacros
  311.  
  312.  A more recent document Q117399, dated November 15, 1994 describes
  313.  disabling automatic macros in Word 6.0.
  314.  
  315.          SUMMARY
  316.  
  317.  The "Microsoft Word Developer's Kit" incorrectly states on page 339 that
  318.  You can use the following command line to disable all auto macros,
  319.  including AutoExec:
  320.  
  321.          winword.exe /mDisableAutoMacros
  322.  
  323.  When executed from the command line, the DisableAutoMacros instruction
  324.  disables ONLY the AutoExec macro but does not disable the AutoNew,
  325.  AutoOpen, AutoClose, or AutoExit macros.
  326.  
  327.          WORKAROUND
  328.  
  329.  To disable all auto macros for the current session of Word, the
  330.  DisableAutoMacros command must be issued from inside a macro. Use the
  331.  following macro to accomplish this:
  332.  
  333.       Sub Main
  334.  
  335.       DisableAutoMacros
  336.  
  337.       End Sub
  338.  
  339.  If you name this macro "DisableAuto" (without the quotation marks), you
  340.  can use the command line "WINWORD.EXE /mDisableAuto" (without the
  341.  quotation marks) to disable all auto macros, including the AutoExec
  342.  macro, for the entire Word session.
  343.  
  344.  To modify the command line, in Program Manager, select the Word for
  345.  Windows icon. From the File menu, choose Properties. Make your changes
  346.  to the command line and choose OK.
  347.  
  348.  The extracts from the Knowledge Base articles presented above are
  349.  copyrighted by Microsoft.
  350.  
  351.  It's interesting to note that the first method applies to all versions
  352.  of Microsoft Word for Windows since version 1.0.  Because of the sheer
  353.  simplicity in creating a DMV, I find it surprising none have formally
  354.  been documented.  There is the possibility that isolated infections
  355.  could have occurred within small pockets of users, for example in a
  356.  corporation, and since conventional virus scanners never reported
  357.  viruses, went undetected.
  358.  
  359.  As an aside, unfortunately the Windows File Manager doesn't support
  360.  being able to associate a document type (such as .DOC) with an
  361.  application and command-line switch.  Unless Word is already running,
  362.  this means there's no way to load Word with the disabled macro switch
  363.  when a .DOC file is double-clicked in the File Manager.  It would
  364.  theoretcially be possible to write a shell application that launches
  365.  Word with auto macros disabled, and associate .DOC files with the shell.
  366.  
  367.  Conclusion
  368.  
  369.  DMVs present a significant threat to computer users that have been
  370.  taught only executable applications can propogate viruses or unleash
  371.  damaging trojan horses.
  372.  
  373.  Because of the simplicity in creating DMVs, it is likely only a matter
  374.  of time before the method is discovered and disseminated among the more
  375.  malicious virus writers.  (I find it amazing I've been able to write so
  376.  much about what is an extremely trivial piece of code.)
  377.  
  378.  A concerted effort needs to be made to educate users of this threat.
  379.  While this is happening, the virus research community should examine all
  380.  applications that feature automatic macros so their characteristics can
  381.  be understood.  Based on this information, existing virus detection
  382.  tools should be modified to scan for automatic macros in data files.
  383.  Finally, software manufacturers need to add functionality to future
  384.  versions of their applications to limit potential damage DMVs can cause.
  385.  
  386.  
  387.  Word DMV Code
  388.  
  389.  The following is the macro code used to create the Word DMV.  If you
  390.  received this file as a Word formatted document, you can also use the
  391.  Macro command in Word's Tools menu to examine the source.
  392.  
  393.  REM This demonstrates an application-specific document virus
  394.  REM generated by an automatic macro in Microsoft Word for
  395.  REM Windows 6.0. Code is executed each time a document is closed.
  396.  REM This macro is only a demonstration, and does not perform any
  397.  REM destructive actions.
  398.  
  399.  REM The purpose of this code is to reveal a significant security
  400.  REM risk in software that supports macro languages with
  401.  REM auto-loading capabilities.  Current virus detection tools are
  402.  REM not presently capable of detecting this type of virus, and
  403.  REM most users are blissfully unaware that threats can come from
  404.  REM documents.
  405.  
  406.  REM Paste this code in the macro Window of a Word document
  407.  REM template. Save the macro as AutoClose.  Enter some random
  408.  REM text in the main word processing window and save the document.
  409.  REM Now copy the file, naming the new file VIRUS.DOC.  Open
  410.  REM VIRUS.DOC in Word.  It will appear as a normal document, but
  411.  REM when you close the document, the virus will execute.
  412.  
  413.  REM Message boxes display progress as the code is executed.
  414.  REM Code is commented.
  415.  
  416.  REM Joel McNamara, December 17, 1994
  417.  REM -----------------------------------------------
  418.  
  419.  Sub MAIN
  420.  title$ ="Document Macro Virus"
  421.  MsgBox "Counting global macros.", title$, 16
  422.  REM check how many macros are globally available.
  423.  total = CountMacros(0)
  424.  present = 0
  425.  
  426.  REM Check and see if the AutoClose macro is installed in global.
  427.  If total > 0 Then
  428.  For cycle = 1 To total
  429.  If MacroName$(cycle, 0) = "AutoClose" Then
  430.  MsgBox "AutoClose macro vir. is already installed in NORMAL.DOT.", title$, 16
  431.          present = 1
  432.  End If
  433.  End If
  434.  
  435.  REM Get the current document name.
  436.  a$ = WindowName$() + ":AutoClose"
  437.  
  438.  REM If AutoClose isn't present, then copy it to NORMAL.DOT.
  439.  If present <> 1 Then
  440.  MacroCopy a$, "Global:AutoClose"
  441.  MsgBox "Infected NORMAL.DOT with copy of AutoClose macro virus.", title$, 16
  442.  
  443.  REM The following code infects a document each time it is closed.
  444.  REM This effectively spreads the macro virus each time an infected
  445.  REM document is opened by Word.
  446.  
  447.  Else
  448.   REM If AutoClose is already global and the file hasn't been
  449.   REM infected yet, save the current file as a
  450.   REM template instead of a document so the macro can be
  451.   REM attached.
  452.  
  453.   REM See if AutoClose is already in the document.  Don't need
  454.   REM to check names because the virus would be the only code
  455.   REM putting a macro in a document.
  456.  
  457.   present = 0
  458.   If CountMacros(1) <> 0 Then
  459.   MsgBox "AutoClose macro virus already present in this document.", title$, 16
  460.   present = 1
  461.   End If
  462.  
  463.   REM Save the document as a template.
  464.  
  465.   If present = 0 Then
  466.   FileSaveAs .Format = 1
  467.   MsgBox "Saved current document as template.", title$, 16
  468.  
  469.   REM Then copy the AutoClose macro from NORMAL.DOT.
  470.  
  471.   MacroCopy "Global:AutoClose", a$
  472.  MsgBox "Infected current doc. with copy of AutoClose macro vir.", title$, 16
  473.  End If
  474.  End If
  475.  
  476.  REM After the document or NORMAL.DOT has been infected, then
  477.  REM execute the following macro code (this could be destructive,
  478.  REM such as a Kill command, invasive, such as a Connect and
  479.  REM CopyFile command, or harmless, with no malacious intent).
  480.  
  481.  MsgBox "Macro vir. has been spread. Now execute some other code.", title$, 16
  482.  End Sub
  483.  
  484.